package com.lagou.homework;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Reducer;

public class HwReducer extends Reducer<IntWritable, IntWritable, IntWritable, IntWritable> {
    IntWritable index = new IntWritable();
    int n;

    @Override
    protected void reduce(IntWritable number, Iterable<IntWritable> values, Context
            context) throws IOException, InterruptedException {
        for (IntWritable v : values) {
            // 1 排序每次累加1
            n += v.get();

            // 2 输出: index为排序序号, number为原始数据
            index.set(n);
            context.write(index, number);
        }
    }
}
